package a09_贪心算法;

/**
 * <p>
 * a02_摆动序列复习2
 * </p>
 *
 * @author flyduck
 * @since 2025/2/10
 */
public class a03_摆动序列复习2 {
    //prev >= 0 && prev < 0
    //prev <= 0 && prev > 0
    public int wiggleMaxLength(int[] nums) {
        int result = 1;//最后一位默认算进去了
        int currIdx = 0;
        int prevDiff = 0;
        while (currIdx < nums.length - 1){
            int currDiff = nums[currIdx + 1] - nums[currIdx];
            if((prevDiff <= 0 && currDiff > 0) || prevDiff >= 0 && currDiff < 0){
                result++;
                prevDiff = currDiff;
            }
            currIdx++;
        }
        return result;
    }
}
